<template>
	<vk-data-dialog
		v-model="value.show"
		:title="page.title"
		:top="page.top"
		:width="page.width"
		:close-on-click-modal="true"
		mode="form"
		@open="onOpen"
		@closed="onClose"
	>
		<!-- 页面主体内容开始 -->
		<vk-data-form
			ref="form1"
			v-model="form1.data"
			:form-type="value.mode"
			:rules="form1.props.rules"
			:action="form1.props.action"
			:columns="form1.props.columns"
			:loading.sync="form1.props.loading"
			:labelWidth="form1.props.labelWidth"
			:show-cancel="page.showCancel"
			:cancel-text="page.cancelText"
			:submit-text="page.submitText"
			@success="onFormSuccess"
		>
			<template v-slot:info="{ form, keyName }">
				<view>
					<view>
						<text class="info-label">订单号</text>
						<text class="info-value">{{ value.item.order_no }}</text>
					</view>
					<view>
						<text class="info-label">付款金额</text>
						<text class="info-value">{{ vk.pubfn.priceFilter(value.item.payment_amount) }} 元</text>
					</view>
					<view>
						<text class="info-label">已退金额</text>
						<text class="info-value">{{ vk.pubfn.priceFilter(value.item.refund_amount) }} 元</text>
					</view>
					<view>
						<text class="info-label">最大可退</text>
						<text class="info-value">{{ vk.pubfn.priceFilter(value.item.payment_amount - value.item.refund_amount) }} 元</text>
					</view>
				</view>
			</template>
		</vk-data-form>
		<!-- 页面主体内容结束 -->
	</vk-data-dialog>
</template>

<script>
var that; // 当前页面对象
var vk = uni.vk; // vk实例
export default {
	props: {
		value: {
			Type: Object,
			default: function() {
				return {
					show: false,
					mode: "",
					item: {}
				};
			}
		}
	},
	data: function() {
		// 组件创建时,进行数据初始化
		return {
			page: {
				title: "充值退款",
				submitText: "确定退款",
				cancelText: "关闭弹窗",
				showCancel: true,
				top: "7vh",
				width: "400px"
			},
			form1: {
				// 表单请求数据，此处可以设置默认值
				data: {},
				// 表单属性
				props: {
					// 表单请求地址
					action: "admin/business/sys.orderRecharge.refund",
					// 表单字段显示规则
					columns: [
						{ key: "info", title: "订单信息", type: "text", showLabel:false },
						{ key: "refund_amount", title: "退款金额", type: "money", max:"", clearable:false },
						{
						  key:"refund_desc", title:"退款描述", type:"textarea",
						  autosize:{ minRows:4, maxRows:10 },
						  maxlength:200,
						  showWordLimit:true,
						}
					],
					// 表单验证规则
					rules: {

					},
					// 左侧label的宽度
					labelWidth: "80px",
				}
			}
		};
	},
	mounted() {
		that = this;
		that.init();
	},
	methods: {
		// 初始化
		init() {
			let { value } = that;
			that.$emit("input", value);
		},
		// 监听 - 页面打开
		onOpen() {
			that = this;
			let { item={} } = that.value;
			// 每次打开时，重新设置表单的值 = value.item 的值，item通过 vk.pubfn.openForm('表单名',{ item:{ _id:"1" } }) 传递值
			let maxRefundAmount = item.payment_amount - item.refund_amount;
			that.form1.data = {
				_id: item._id,
				refund_amount: maxRefundAmount,
			}
			let column = vk.pubfn.getListItem(that.form1.props.columns, "key", "refund_amount");
			column.max = vk.pubfn.toDecimal(maxRefundAmount/100, 2) ;
		},
		// 监听 - 页面关闭
		onClose() {
			//that.$refs.form1.resetForm(); // 关闭时，重置表单
		},
		// 监听 - 提交成功后
		onFormSuccess() {
			that.value.show = false; // 关闭页面
			that.$emit("success");
		}
	},
	watch: {

	},
	// 计算属性
	computed: {

	}
};
</script>

<style lang="scss" scoped>
	.info-label{
		width: 80px;
		display: inline-block;
		padding-right: 10px;
		text-align: right;
		box-sizing:border-box;
	}
</style>
